package org.fungee.core;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;

import org.fungee.core.exception.LoadObjectAttributesFromPropertiesException;
import org.fungee.core.graphics.GraphicAttribute;
import org.fungee.core.physics.PhysicAttribute;


public abstract class FungeeObject{
	
	protected ArrayList<PhysicAttribute> physicAttributes;
	protected ArrayList<GraphicAttribute> graphicAttributes;
	
	public ArrayList<PhysicAttribute> getPhysicAttributes() {
		return physicAttributes;
	}

	public void setPhysicAttributes(ArrayList<PhysicAttribute> physicAttributes) {
		this.physicAttributes = physicAttributes;
	}

	public ArrayList<GraphicAttribute> getGraphicAttributes() {
		return graphicAttributes;
	}

	public void setGraphicAttributes(ArrayList<GraphicAttribute> graphicAttributes) {
		this.graphicAttributes = graphicAttributes;
	}

	protected FungeeObject() {
		
	}

	private void loadObjectAttributeFromProperties(Properties property, ArrayList<? extends FungeeAttribute> list) throws LoadObjectAttributesFromPropertiesException{
		Iterator<? extends FungeeAttribute> iterator = list.iterator();
		while(iterator.hasNext()){
			FungeeAttribute attribute = iterator.next();
			try{
				attribute.loadObjectAttributesFromProperties(property);
			}
			catch (LoadObjectAttributesFromPropertiesException e) {
				String message = " exception raised from " + attribute.getClass().getCanonicalName();
				e.setMessage(e.getMessage() + message);
				throw e;
			}
		}
	}

	public void loadObjectAttributesFromProperties(Properties property) throws LoadObjectAttributesFromPropertiesException {
		loadObjectAttributeFromProperties(property, this.graphicAttributes);
		loadObjectAttributeFromProperties(property, this.physicAttributes);
	}

	
}
